package com.xu.demo.core.util;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

public class MybatisPlusGenerator {
    private static final String db_url = "jdbc:dm://127.0.0.1:5236";
    private static final String db_username = "SYSDBA";
    private static final String db_password = "SYSDBA";

//    private static final String db_url = "jdbc:mysql://127.0.0.1:3306/zfhf?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8";
//    private static final String db_username = "root";
//    private static final String db_password = "123456";
    private static final String generator_author = "xujing";
    private static final String generator_parent_package = "com.gykj.gzy.dataservice";
//    private static final String generator_path = "D:\\work\\java\\gzy-dataservice\\src\\main\\java";
    private static final String generator_path = "D:\\";

    public static void main(String[] args) {
        //https://baomidou.com/pages/981406/ 配置文档地址
        DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder(db_url, db_username, db_password)
                                            .schema("JY_DMS_DATASOURCE")
                                            .build();

        GlobalConfig globalConfig = new GlobalConfig.Builder()
                .fileOverride()
                .enableSwagger()
                .author(generator_author)
                .outputDir(generator_path)
                .build();

        PackageConfig packageConfig = new PackageConfig.Builder()
                .parent(generator_parent_package)
                .build();

        StrategyConfig strategyConfig = new StrategyConfig.Builder()
                .enableSkipView()// 跳过视图
//                .addTablePrefix("form_")
                .enableCapitalMode()
//                .enableSchema()
                .mapperBuilder()
                .enableBaseResultMap()
                .enableBaseColumnList()
                .entityBuilder()
                .enableTableFieldAnnotation()
                .enableLombok()
                .build();

        TemplateConfig build = new TemplateConfig.Builder().build();

        AutoGenerator generator = new AutoGenerator(dataSourceConfig);
        generator.global(globalConfig);
        generator.packageInfo(packageConfig);


        generator.strategy(strategyConfig);
        generator.template(build);
        generator.execute(new FreemarkerTemplateEngine());
    }
}
